﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using Test.DAL;
using Test.IDAL;

namespace Test_Stu
{
    public partial class StuInfo : System.Web.UI.Page
    {
        IStuInfoDAL bll = new StuInfoDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.DataSource = bll.Select();
            GridView1.DataBind();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var data = e.Keys["Id"];
            int id = Convert.ToInt32(data);
            var result = bll.Delete(new Test.Model.StuInfo() { Id = id });

            if (result.States && result.Data > 0)
            {
                var url = Request.Url.PathAndQuery;
                Response.Redirect(url);
            }
            else {
                Response.Write("<script>alert('" + result.message + "')</script>");
            }
        }
    }
}